//
//  ShoppingViewController.m
//  CivilianTravel
//
//  Created by xalo on 16/7/16.
//  Copyright © 2016年 许仕杰. All rights reserved.
//

#import "ShoppingViewController.h"
#import "SpecificModol.h"
#import "TourViewController.h"



@interface ShoppingViewController ()

@property (weak, nonatomic) IBOutlet UIImageView *imageName;

@property (weak, nonatomic) IBOutlet UITableView *tableView;


@end

@interface ShoppingViewController ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong)UIScrollView *scrollView;

@property(nonatomic,strong)NSMutableArray *extDataArray;

@property (nonatomic,strong)NSMutableArray *big;


@property (nonatomic, strong) NSMutableArray *contentArray;

@property (nonatomic, strong) NSMutableArray *urlArray;


@end

@implementation ShoppingViewController
-(NSMutableArray *)urlArray{
    if (!_urlArray) {
        _urlArray = [NSMutableArray array];
    }
    return _urlArray;
}
-(NSMutableArray *)contentArray{
    if (!_contentArray) {
        _contentArray = [NSMutableArray array];
    }
    return _contentArray;
}

-(NSMutableArray *)extDataArray{
    if (!_extDataArray) {
        _extDataArray = [NSMutableArray array];
        
    }
    return _extDataArray;
}





- (void)viewDidLoad {
    [super viewDidLoad];
    //   数据少时隐藏最后面的线
   self.tableView.tableFooterView = [[UIView alloc]init];

    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;// 隐藏线条
    self.tableView.dataSource = self;
    self.tableView.delegate = self;

    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
  
    [self requestSpotWithCityId:self.VCid];

     }





-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        return 5;
    }else  {
        return 20;
    }
    
  
}

//  返回分组
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0) {
       return self.big.count;
    }else{
        return self.extDataArray.count;
    
    }

}

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    if (section == 1) {
           return @"更多服务 ";
    }else{
        return nil;
    }
    
 
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (indexPath.section==0) {

        
        
      
          cell.textLabel.text = self.big[indexPath.row];
        
    }else{
        cell.textLabel.text = self.extDataArray[indexPath.row];
    }

      cell.textLabel.numberOfLines = 0;

    
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    tableView.estimatedRowHeight = 5;
    tableView.rowHeight = UITableViewAutomaticDimension;
    return tableView.rowHeight;
}


//   数据请求
-(void)requestSpotWithCityId:(NSNumber *)cityId{
    
    [RequestManager fetchDataWithUrl:@"http://www.roadqu.com/api/mobile/qunawan/poi/detail" parameter:@{@"a_t":@"1468411049000",@"token":@"578624ce19a3f",@"code":cityId,@"sign":@"e8cfbbc7ec43d16cba2dfb01556e06ee19d2b57f"} method:@"POST" compeleted:^(NSData *data) {
        
           NSDictionary *BigDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];

     
        SpecificModol *modol = [[SpecificModol alloc]init];
        [modol setValuesForKeysWithDictionary:BigDic[@"data"]];
       
             NSString *opentime = [NSString stringWithFormat:@"开放时间: %@",modol.opentime];
        
       
        NSString *descriptio = [NSString stringWithFormat:@"景点简介:%@",modol.descriptio];
    
             NSString *traffic = [NSString stringWithFormat:@"景点价格: %@",modol.price];
      
       
        NSString *telephone = [NSString stringWithFormat:@"景点电话: %@",modol.telephone];
        
        NSString *cityname = [NSString stringWithFormat:@"景点名称: %@",modol.name];
        self.big = [NSMutableArray arrayWithObjects:opentime,descriptio,traffic,telephone,cityname, nil];

        
        
        
         for (NSDictionary *dicext in BigDic[@"data"][@"ext"]) {
            
          NSString *string = [NSString stringWithFormat:@"%@:%@",dicext[@"name"],dicext[@"content"]];

            [self.extDataArray addObject:string];
        
            
        }
 
        for ( NSDictionary *impreDic in BigDic[@"data"][@"impress"] ) {


            

            [self.imageName sd_setImageWithURL:[NSURL URLWithString:impreDic[@"url"]] placeholderImage:[UIImage imageNamed:@"travel.jpg"]];

                  }
        

        
        
        
    } updateUI:^{

        
      
        
        [self.tableView reloadData];
        
    }];
}


//  跳转到导游页面
- (IBAction)buttClick:(id)sender {
    TourViewController *tou = [[TourViewController alloc]init];
    [self.navigationController pushViewController:tou animated:YES];
    
    
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
